﻿CREATE FUNCTION [dbo].[fn_ColumnListAll]
(
	@Table sysname
)
RETURNS VARCHAR(MAX)
AS
BEGIN
	DECLARE @ColumnList VARCHAR(MAX)
	
	SELECT @ColumnList = COALESCE(@ColumnList + ',', '') + c.[name]
	FROM   sys.tables t
	       INNER JOIN sys.[columns] c
	            ON  t.[object_id] = c.[object_id]
	WHERE  t.[name] = @Table
	       AND t.[type] = 'U'
	
	RETURN @ColumnList
END